<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/layuimini/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            {{# if(d.install_time == ''){ }}
                <a class="layui-btn layui-btn-normal layui-btn-xs data-count-install" lay-event="install">安装</a>
            {{# } else { }}
                <a class="layui-btn layui-btn-xs layui-btn-danger data-count-uninstall" lay-event="uninstall">卸载</a>
            {{# } }}
        </script>
    </div>
</div>
<script src="/static/admin/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: "{:url('Module/index')}"+'?_action=getModuleList',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'module', title: '模块'},
                {field: 'modulename', title: '模块名称'},
                {field: 'introduce', title: '介绍'},
                {field: 'author', title: '作者'},
                {field: 'version', title: '版本'},
                {field: 'adaptation', title: '最低后台版本'},
                {field: 'install_time', title: '安装时间', minWidth: 170,templet: function (d) {
                        if (d.install_time == '') {
                            return '未安装';
                        } else {
                            return d.install_time;
                        }
                    }},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            // skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: data.field
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
           
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'install') {
                $.ajax({
                    url: "{:url('Module/install')}",
                    type: 'post',
                    dataType: 'json',
                    data:{module:data.module},
                    success: function (data) {
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                table.reload('currentTableId');
                            });
                    },
                    error: function (xhr, textstatus, thrown) {
                        return layer.msg('Status:' + xhr.status + '，' + xhr.statusText + '，请稍后再试！');
                    }
                });
            } else if (obj.event === 'uninstall') {
                $.ajax({
                    url: "{:url('Module/unInstall')}",
                    type: 'post',
                    dataType: 'json',
                    data:{module:data.module},
                    success: function (data) {
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                table.reload('currentTableId');
                            });
                    },
                    error: function (xhr, textstatus, thrown) {
                        return layer.msg('Status:' + xhr.status + '，' + xhr.statusText + '，请稍后再试！');
                    }
                });
            }
        });

    });
</script>

</body>
</html>